package com.itheima.spring.tuling.iocbeanlifecicle;

import java.util.ArrayList;
import java.util.List;

/**
 * 对list中元素进行排序
 * 自定义list排序规则
 */
public class MainStarterv2 {

	public static void main(String[] args) {
		List<Tank> list=new ArrayList<>();
		Tank tank2=new Tank();
		tank2.setName("坦克2号");
		tank2.setIndex(2);
		list.add(tank2);

		Tank tank=new Tank();
		tank.setName("坦克1号");
		tank.setIndex(1);
		list.add(tank);

		list.sort((o1, o2) -> {
			return Integer.compare(o1.getIndex(), o2.getIndex());
		});

		list.forEach(tank1 -> System.out.println(tank1.getIndex()));
	}
}
